package com.hxci.zhangcong.tool;

import com.hxci.zhangcong.pojo.Course;
import com.hxci.zhangcong.servcie.CorseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;

import java.util.List;
import java.util.function.Function;

@Configuration
public class CourseTools {
	@Autowired
	private CorseService corseService;

	//private static final Logger logger = LoggerFactory.getLogger(CorseService.class);



	public record DeleteCourseDatesRequest(String sno) {
	}

	public record AddCourseDataRequest(Course course) {
	}
	public record CourseDetailsRequest(String teacher) {
	}





	@Bean
	@Description("删除课程")
	public Function<DeleteCourseDatesRequest, String> deleteCourse() {
		return request -> {
			System.out.println(request.sno);
			Integer flag = corseService.del(request.sno);
//			flightBookingService.changeBooking(request.bookingNumber(), request.name(), request.date(), request.from(),
//					request.to());
			return "";
		};
	}

	@Bean
	@Description("添加课程")
	public Function<AddCourseDataRequest, String> addCourse() {
		return request -> {
			System.out.println(request.course);
     		corseService.save(request.course);
			return "";
		};
	}

	@Bean
	@Description("获取课程")
	public Function<CourseDetailsRequest,List<Course>> getCourseDetails() {
		return request -> {
			System.out.println(request.teacher);
			List<Course> courses =corseService.queryByTeacher(request.teacher);
			return courses;
		};
	}

}
